// 定义计分牌类
class ScorePanel {
  //  用来记录分数和等级
  score: number = 0;
  level: number = 1;
  //    记录分数和等级的元素
  scoreEle: HTMLElement;
  levelEle: HTMLElement;
  //   设置变量限制等级
  maxLevel: number;
  //   设置变量表示多少分生一次级
  upScore: number;
  constructor(maxLevel: number = 10, upScore: number = 10) {
    this.scoreEle = document.getElementById("score")!;
    this.levelEle = document.getElementById("level")!;
    this.maxLevel = maxLevel;
    this.upScore = upScore;
  }
  //   加分方法
  addScore(): void {
    this.score++;
    this.scoreEle.innerHTML = this.score + "";
    if (this.score % this.upScore === 0) {
      this.levelUp();
    }
  }

  //   等级提升的方法
  levelUp(): void {
    if (this.level < this.maxLevel) {
      this.level++;
      this.levelEle.innerHTML = this.level + "";
    }
  }
}
export default ScorePanel